/**
 * 游戏进度聚合服务
 */
import { fetchUserGameData } from '@/api/game';
import { getCurrentUserInfo } from '@/utils/auth';

export const ProgressService = {
  async getUserProgress(userId) {
    const [snakeData, blockData, rogueData] = await Promise.all([
      this.getSnakeProgress(userId),
      this.getBlockCollectorProgress(userId),
      this.getRoguelikeProgress(userId)
    ]);
    
    // 计算总探索度
    const totalProgress = 
      (snakeData.progress + blockData.progress + rogueData.progress) / 3;
    
    return {
      totalProgress,
      games: {
        snake: snakeData,
        blockCollector: blockData,
        roguelike: rogueData
      }
    };
  },
  
  async getSnakeProgress(userId) {
    const data = await fetchUserGameData(userId, 'snake');
    const maxLength = data.maxLength || 0;
    
    // 假设300是最大长度
    const progress = Math.min(maxLength / 300, 1);
    
    return {
      gameName: '贪吃蛇',
      progress,
      stats: {
        '最长记录': `${maxLength} 米`,
        '最高分': data.highScore || 0
      }
    };
  },
  
  async getBlockCollectorProgress(userId) {
    const data = await fetchUserGameData(userId, 'blockCollector');
    const blocksCollected = data.blocksCollected || 0;
    
    // 假设1000是最大收集数
    const progress = Math.min(blocksCollected / 1000, 1);
    
    return {
      gameName: '方块收集',
      progress,
      stats: {
        '收集方块': blocksCollected,
        '最高连击': data.maxCombo || 0
      }
    };
  },
  
  async getRoguelikeProgress(userId) {
    const data = await fetchUserGameData(userId, 'roguelike');
    const floorsCleared = data.floorsCleared || 0;
    
    // 假设10是最大层数
    const progress = Math.min(floorsCleared / 10, 1);
    
    return {
      gameName: '肉鸽游戏',
      progress,
      stats: {
        '通关层数': floorsCleared,
        '击败敌人': data.enemiesDefeated || 0
      }
    };
  }
}; 